
package com.geek.bams.client;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;

public class MainPanel extends JPanel {
    private ATMClient atm;

    public MainPanel(ATMClient atm) {
        this.atm = atm;
        initComponents();
    }
    //跳转注册界面  在JPanel画布，右键ActionEvent
    private void register(ActionEvent e) {
        // TODO add your code here
        //获取当前MainPanel的父窗口（ATMClient），的布局方式，即卡片式布局
        CardLayout cardLayout = (CardLayout)this.getParent().getLayout();
        //指定跳转至登录界面
        cardLayout.show(this.getParent() , "registerPanel");
    }
    //跳转登录界面   在JPanel画布，右键ActionEvent
    private void login(ActionEvent e) {
        // TODO add your code here
        //获取当前MainPanel的父窗口（ATMClient），的布局方式，即卡片式布局
        CardLayout cardLayout = (CardLayout)this.getParent().getLayout();
        //指定跳转至登录界面
        cardLayout.show(this.getParent() , "loginPanel");
    }

    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents  @formatter:off
        mainLabel = new JLabel();
        registerButton = new JButton();
        loginButton = new JButton();

        //======== this ========
        setLayout(null);

        //---- mainLabel ----
        mainLabel.setText("\u6a21\u62df ICBC ATM \u7ec8\u7aef");
        mainLabel.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 24));
        mainLabel.setHorizontalAlignment(SwingConstants.CENTER);
        add(mainLabel);
        mainLabel.setBounds(110, 80, 240, 40);

        //---- registerButton ----
        registerButton.setText("\u6ce8\u518c");
        registerButton.addActionListener(e -> register(e));
        add(registerButton);
        registerButton.setBounds(85, 345, 80, 30);

        //---- loginButton ----
        loginButton.setText("\u767b\u5f55");
        loginButton.addActionListener(e -> login(e));
        add(loginButton);
        loginButton.setBounds(300, 345, 80, 30);

        setPreferredSize(new Dimension(500, 650));
        // JFormDesigner - End of component initialization  //GEN-END:initComponents  @formatter:on
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables  @formatter:off
    private JLabel mainLabel;
    private JButton registerButton;
    private JButton loginButton;
    // JFormDesigner - End of variables declaration  //GEN-END:variables  @formatter:on
}
